Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustc: fix building with llvm #320432

Merged
merged 1 commit into from
Jul 25, 2024
Merged

Conversation

RossComputerGuy
Copy link
Member

@RossComputerGuy RossComputerGuy commented Jun 17, 2024

Description of changes

Fixes #311930

Can be tested / reproduced by building pkgsLLVM.rustc. Fix was tested under the Nixpkgs LLVM Workspace project.

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 24.11 Release Notes (or backporting 23.11 and 24.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@RossComputerGuy RossComputerGuy marked this pull request as ready for review June 17, 2024 05:56
@ofborg ofborg bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild 10.rebuild-linux: 0 This PR does not cause any packages to rebuild labels Jun 17, 2024
@tomberek
Copy link
Contributor

I still get this on x86_64-linux:

      >   = note: /nix/store/wwfrj9kvfi14xclc38qfwm71ah6aawdh-binutils-2.41/bin/ld: cannot find -lgcc_s: No such file or directory
       >           clang: error: linker command failed with exit code 1 (use -v to see invocation)
       >
       >
       > error: could not compile `typenum` (build script) due to 1 previous error
       > failed to run: /nix/store/qyw7qc22j2ngf9wip8sxagaxb0387gnq-cargo-1.78.0/bin/cargo build --manifest-path /build/rustc-1.78.0-src/src/bootstrap/Cargo.toml --frozen

@RossComputerGuy
Copy link
Member Author

@tomberek Yes, this seems to still occur on aarch64-linux as well. Not entirely sure why we are still facing this issue. Looking at the documentation comments in config.example.toml in rust, it should work. Likely an upstream issue with rustc not detecting things right?

@RossComputerGuy
Copy link
Member Author

@ofborg build pkgsLLVM.rustc

@jopejoe1
Copy link
Member

On x86_64-linux I'm getting:

       >   = note: /nix/store/wwfrj9kvfi14xclc38qfwm71ah6aawdh-binutils-2.41/bin/ld: cannot find -lstdc++: No such file or directory
       >           clang: error: linker command failed with exit code 1 (use -v to see invocation)
       >           
       >
       > error: could not compile `rustix` (build script) due to 1 previous error
       > error: linking with `/nix/store/pyhikk3r5zr1h5mg06k94j9bsl2lgyqv-x86_64-unknown-linux-gnu-clang-wrapper-17.0.6/bin/x86_64-unknown-linux-gnu-clang` failed: exit status: 1

@RossComputerGuy RossComputerGuy marked this pull request as draft June 22, 2024 20:45
@RossComputerGuy
Copy link
Member Author

@jopejoe1 Thank you for testing, I marked it as a draft and will continue figuring out why rustc still doesn't compile tonight.

@paparodeo
Copy link
Contributor

On x86_64-linux I'm getting:

       >   = note: /nix/store/wwfrj9kvfi14xclc38qfwm71ah6aawdh-binutils-2.41/bin/ld: cannot find -lstdc++: No such file or directory

perhaps we should be compiling the pkgsLLVM clang so that it translates the -lstdc++ to -lc++ by default. this is the behavior for systems where the default c++ library is -lc++. there is somewhat of a discussion about this translation as it relates to darwin: #273016 (comment)

alternatively, adding the flag -stdlib=libc++ should also work

@RossComputerGuy
Copy link
Member Author

@RossComputerGuy
Copy link
Member Author

RossComputerGuy commented Jul 5, 2024

Rustc builds now 🎉

(Will let CI run through and if labels do not change, will retarget for staging)

@RossComputerGuy RossComputerGuy marked this pull request as ready for review July 5, 2024 21:43
@RossComputerGuy
Copy link
Member Author

@ofborg build pkgsLLVM.rustc

@RossComputerGuy RossComputerGuy marked this pull request as draft July 6, 2024 00:23
@RossComputerGuy RossComputerGuy changed the base branch from master to staging July 6, 2024 00:26
@RossComputerGuy RossComputerGuy marked this pull request as ready for review July 6, 2024 00:26
@@ -66,14 +67,14 @@ in stdenv.mkDerivation (finalAttrs: {
# when linking stage1 libstd: cc: undefined reference to `__cxa_begin_catch'
# This doesn't apply to cross-building for FreeBSD because the host
# uses libstdc++, but the target (used for building std) uses libc++
optional (stdenv.isLinux && !withBundledLLVM && !stdenv.targetPlatform.isFreeBSD) "--push-state --as-needed -lstdc++ --pop-state"
optional (stdenv.isLinux && !withBundledLLVM && !stdenv.targetPlatform.isFreeBSD && !useLLVM) "--push-state --as-needed -lstdc++ --pop-state"
++ optional (stdenv.isLinux && !withBundledLLVM && !stdenv.targetPlatform.isFreeBSD && useLLVM) "--push-state --as-needed -L${llvmPackages.libcxx}/lib -lc++ -lc++abi -lLLVM-${lib.versions.major llvmPackages.llvm.version} --pop-state"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
++ optional (stdenv.isLinux && !withBundledLLVM && !stdenv.targetPlatform.isFreeBSD && useLLVM) "--push-state --as-needed -L${llvmPackages.libcxx}/lib -lc++ -lc++abi -lLLVM-${lib.versions.major llvmPackages.llvm.version} --pop-state"
++ optional (stdenv.isLinux && !withBundledLLVM && !stdenv.targetPlatform.isFreeBSD && useLLVM)
"--push-state --as-needed -L${llvmPackages.libcxx}/lib -lc++ -lc++abi -lLLVM-${lib.versions.major llvmPackages.llvm.version} --pop-state"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -66,14 +67,14 @@ in stdenv.mkDerivation (finalAttrs: {
# when linking stage1 libstd: cc: undefined reference to `__cxa_begin_catch'
# This doesn't apply to cross-building for FreeBSD because the host
# uses libstdc++, but the target (used for building std) uses libc++
optional (stdenv.isLinux && !withBundledLLVM && !stdenv.targetPlatform.isFreeBSD) "--push-state --as-needed -lstdc++ --pop-state"
optional (stdenv.isLinux && !withBundledLLVM && !stdenv.targetPlatform.isFreeBSD && !useLLVM) "--push-state --as-needed -lstdc++ --pop-state"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
optional (stdenv.isLinux && !withBundledLLVM && !stdenv.targetPlatform.isFreeBSD && !useLLVM) "--push-state --as-needed -lstdc++ --pop-state"
optional (stdenv.isLinux && !withBundledLLVM && !stdenv.targetPlatform.isFreeBSD && !useLLVM)
"--push-state --as-needed -lstdc++ --pop-state"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/prs-ready-for-review/3032/4278

@tomberek
Copy link
Contributor

For aarch64-darwin:

       > [508/511] Linking C static library lib/builtins/libclang_rt.builtins_arm64_osx.a
       > [509/511] Generating ../darwin/libclang_rt.osx.a
       > FAILED: lib/darwin/libclang_rt.osx.a /tmp/nix-build-compiler-rt-libc-aarch64-apple-darwin-16.0.6.drv-0/compiler-rt-src-16.0.6/compiler-rt/build/lib/darwin/libclang_rt.osx.a
       > cd /tmp/nix-build-compiler-rt-libc-aarch64-apple-darwin-16.0.6.drv-0/compiler-rt-src-16.0.6/compiler-rt/build/lib/builtins && /nix/store/b4lfys8gkiwwdad8nxsdfhzvy5gzi1jw-cmake-3.29.6/bin/cmake -E make_directory /tmp/nix-build-compiler-rt-libc-aarch64-apple-darwin-16.0.6.drv-0/compiler-rt-src-16.0.6/compiler-rt/build/lib/darwin && /nix/store/5pn1viwwkw60f9gcrcbcsg9792rrlpgz-llvm-binutils-16.0.6/bin/aarch64-apple-darwin-lipo -output /tmp/nix-build-compiler-rt-libc-aarch64-apple-darwin-16.0.6.drv-0/compiler-rt-src-16.0.6/compiler-rt/build/lib/darwin/libclang_rt.osx.a -create -arch arm64 /tmp/nix-build-compiler-rt-libc-aarch64-apple-darwin-16.0.6.drv-0/compiler-rt-src-16.0.6/compiler-rt/build/lib/builtins/libclang_rt.builtins_arm64_osx.a
       > /bin/sh: /nix/store/5pn1viwwkw60f9gcrcbcsg9792rrlpgz-llvm-binutils-16.0.6/bin/aarch64-apple-darwin-lipo: No such file or directory
       > [510/511] Linking C static library lib/builtins/libclang_rt.cc_kext_arm64_osx.a
       > ninja: build stopped: subcommand failed.
       For full logs, run 'nix log /nix/store/9aczpyanlpj3d291d9zfxfajfvg0rs58-compiler-rt-libc-aarch64-apple-darwin-16.0.6.drv'.

@RossComputerGuy
Copy link
Member Author

@tomberek I've pushed a change which I believe might fix it, if it doesn't then I'll do some more diagnosing tonight.

@tomberek tomberek merged commit 6a163e2 into NixOS:staging Jul 25, 2024
24 of 26 checks passed
@tomberek
Copy link
Contributor

Builds on x86_64-linux.

@trofi
Copy link
Contributor

trofi commented Jul 28, 2024

Bisect says 6a163e2 rustc: fix building with llvm (#320432) broke the eval of pkgsLLVM.betterbird-unwrapped on staging as:

$ nix-instantiate -A pkgsLLVM.betterbird-unwrapped
error:
       … while calling a functor (an attribute set with a '__functor' attribute)
         at lib/customisation.nix:264:13:
          263|     in if missingArgs == {}
          264|        then makeOverridable f allArgs
             |             ^
          265|        # This needs to be an abort so it can't be caught with `builtins.tryEval`,

       … while evaluating a branch condition
         at lib/customisation.nix:148:7:
          147|     in
          148|       if isAttrs result then
             |       ^
          149|         result // {

       (stack trace truncated; use '--show-trace' to show the full, detailed trace)

       error: attribute 'override' missing
       at pkgs/applications/networking/browsers/firefox/common.nix:167:18:
          166|   # Force the use of lld and other llvm tools for LTO
          167|   llvmPackages = llvmPackages0.override {
             |                  ^
          168|     bootBintoolsNoLibc = null;

@RossComputerGuy
Copy link
Member Author

@trofi Will take a look at it tonight. Tbf, it probably wouldn't even have built anyway so it's not like we totally broke everything.

@trofi
Copy link
Contributor

trofi commented Jul 28, 2024

My concern is the eval only (I usually scan for things in treewide evals). It used to eval successfully and does not anymore.

@RossComputerGuy
Copy link
Member Author

Heh yeah, I'll take a look tonight after work to try fixing this. Unless someone else wants to touch this.

@rhelmot rhelmot mentioned this pull request Sep 5, 2024
13 tasks
artemist added a commit to rhelmot/nixpkgs that referenced this pull request Nov 2, 2024
The PR which fixed `useLLVM` native rustc builds (NixOS#320432)
also broke cross builds.

The C compiler it used for `llvmShared` and `llvmPackages`,
`llvmPackages.clangUseLLVM`, was built to run on the host
and create binaries for the target (`pkgsHostTarget`).
Instead, the compiler should be built to run on the build
machine and produce binaries for the build machine (`pkgsBuildHost`).

Replace the overridden compilers with ones from `pkgsBuildHost`

Co-Authored-By: Artemis Tosini <me@artem.ist>
artemist added a commit to rhelmot/nixpkgs that referenced this pull request Nov 2, 2024
The PR which fixed `useLLVM` native rustc builds (NixOS#320432)
also broke cross builds.

The C compiler it used to produce `llvmShared` and `llvmPackages`,
`llvmPackages.clangUseLLVM`, was built to run on the host
and create binaries for the target (`pkgsHostTarget`).
Instead, the compiler should be built to run on the build
machine and produce binaries for the host machine (`pkgsBuildHost`).

Replace the overridden compilers with ones from `pkgsBuildHost`

Co-Authored-By: Artemis Tosini <me@artem.ist>
Shawn8901 pushed a commit to Shawn8901/nixpkgs that referenced this pull request Nov 3, 2024
The PR which fixed `useLLVM` native rustc builds (NixOS#320432)
also broke cross builds.

The C compiler it used to produce `llvmShared` and `llvmPackages`,
`llvmPackages.clangUseLLVM`, was built to run on the host
and create binaries for the target (`pkgsHostTarget`).
Instead, the compiler should be built to run on the build
machine and produce binaries for the host machine (`pkgsBuildHost`).

Replace the overridden compilers with ones from `pkgsBuildHost`

Co-Authored-By: Artemis Tosini <me@artem.ist>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Build failure: rustc on LLVM stdenv
7 participants